package cn.wolfcode.crm.util;


import cn.wolfcode.crm.domain.Employee;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class UserContext {

    public static Session getSession() {
        //通过shiro的方式获取会话对象
        return SecurityUtils.getSubject().getSession();
    }

    public static Employee getCurrentUser() {
        //通过shiro的方式获取当前登录用户
        return (Employee) SecurityUtils.getSubject().getPrincipal();
    }

    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) (RequestContextHolder.getRequestAttributes());
        return requestAttributes.getRequest();
    }
    //生成指定长度随机数
    public static String getRandom(int l){
        String random = "" ;
        for (int i = 0; i < l; i++) {
            int a= (int) (Math.random() * 10);
            random = random + a ;
        }
        return random;
    }


}
